package com.chuji.crmcj.act;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.android.volley.Response;
import com.chuji.crmcj.R;
import com.chuji.crmcj.adapter.PotentialAdapter;
import com.chuji.crmcj.adapter.PotentialListAdapter;
import com.chuji.crmcj.adapter.downListAdapter;
import com.chuji.crmcj.adapter.potentMagAda;
import com.chuji.crmcj.bean.CarModelInfo;
import com.chuji.crmcj.bean.PotenMagInfo;
import com.chuji.crmcj.bean.PotentialInfo;
import com.chuji.crmcj.bean.SearchPotenInfo;
import com.chuji.crmcj.utils.SPUtils;
import com.chuji.crmcj.utils.UIUtils;
import com.chuji.crmcj.utils.UrlUtils;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by w.pitt on 2016/1/13.
 * 潜在客户
 */
public class PotentialListAct extends BaseActivity implements View.OnClickListener, AdapterView.OnItemClickListener {
    private PullToRefreshListView mLvPotential;
    private PotentialAdapter potentialAdapter;
    private PotentialListAdapter potListadapter;
    private ImageView mIvBack;
    private EditText mEtSearch;
    private RelativeLayout mCarSort;
    private RelativeLayout mCusSort;
    private RelativeLayout mTimeSort;
    private ImageView mIvCarIcon;
    private ImageView mIvCusIcon;
    private ImageView mIvTimeIcon;
    //popuwindow的宽度
    private int width;
    private TextView mTvCar;
    private TextView mTvCus;
    private TextView mTvTime;
    private List<String> mLevels;
    private PopupWindow mPwLevel;
    private PopupWindow mPwCarModel;
    private int roleType;
    private com.chuji.crmcj.adapter.potentMagAda potentMagAda;
    private PotenMagInfo potenMagInfo;
    private PotentialInfo potentialInfo;
    private String userId;
    private String companyID;
    private CarModelInfo carModelInfo;
    private View ll_left1;
    private List<PotentialInfo.ApiParamObjEntity> list;
    private List<PotenMagInfo.ApiParamObjEntity> mMagList;
    private SearchPotenInfo searchPotenInfo;
    private FrameLayout mFlContent;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_potential);
        mFlContent = (FrameLayout) findViewById(R.id.fl_content);
        mCarSort = (RelativeLayout) findViewById(R.id.rl_car_sort);
        mCusSort = (RelativeLayout) findViewById(R.id.rl_cus_sort);
        mTimeSort = (RelativeLayout) findViewById(R.id.rl_time_sort);
        ll_left1 = findViewById(R.id.ll_left1);

        mTvCar = (TextView) findViewById(R.id.tv_category);
        mTvCus = (TextView) findViewById(R.id.tv_cus_sort);
        mTvTime = (TextView) findViewById(R.id.tv_time_sort);
        mIvCarIcon = (ImageView) findViewById(R.id.iv_car_icon);
        mIvCusIcon = (ImageView) findViewById(R.id.iv_cus_icon);
        mIvTimeIcon = (ImageView) findViewById(R.id.iv_time_icon);

        mLvPotential = (PullToRefreshListView) findViewById(R.id.lv_potential);
        mEtSearch = (EditText) findViewById(R.id.et_search);
//        mLvPotential.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        //lv设置

        mLvPotential.getRefreshableView().setDivider(null);
        mLvPotential.getRefreshableView().setSelector(android.R.color.transparent);

        /*测量拿到宽*/
        DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);
        width = metric.widthPixels;
    }

    @Override
    protected void initData() {
        roleType = SPUtils.getInt(UIUtils.getContext(), "RoleType", -1);
        userId = SPUtils.getString(UIUtils.getContext(), "UserID", "");
        companyID = SPUtils.getString(UIUtils.getContext(), "CompanyID", "");

        reqCallCarModel();

        if (roleType == 1) {
            mLvPotential.setMode(PullToRefreshBase.Mode.PULL_FROM_END);
            reqDataBySale(0, 1);
        } else {
            reqDataByMag(0);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        mLvPotential.getRefreshableView().setSelection(0);
    }

    List<CarModelInfo.ApiParamObjEntity> mCalModelInfo;

    private void reqCallCarModel() {
        String strURL = String.format(UrlUtils.GetCarModelByCompanyID + "&CompanyID=%s", companyID);
        volleyRequest(strURL, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                carModelInfo = JSON.parseObject(s, CarModelInfo.class);
                UIUtils.runInMainThread(new Runnable() {
                    @Override
                    public void run() {
                        mCalModelInfo = new ArrayList<CarModelInfo.ApiParamObjEntity>();
                        if (carModelInfo.getApiParamObj().size() != 0) {
                            for (int i = 0; i < carModelInfo.getApiParamObj().size(); i++) {
                                mCalModelInfo.add(carModelInfo.getApiParamObj().get(i));
                                mDatas.add(carModelInfo.getApiParamObj().get(i).getCarModel());
                            }
                        }
                    }
                });
            }
        });
    }

    private String orderBy = "desc";

    //desc/asc
    private void reqDataByMag(final int type) {
        String strURL = String.format(UrlUtils.PossibleCustomerPeter + "&UserID=%s&CarModel=%s&CustomerLevel=%s&OrderBy=%s", userId, carModel, customeLevel, orderBy);
        volleyRequest(strURL, new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        potenMagInfo = JSON.parseObject(s, PotenMagInfo.class);
                        UIUtils.runInMainThread(new Runnable() {
                            @Override
                            public void run() {
                                if (potentMagAda == null) {
                                    mMagList = potenMagInfo.getApiParamObj();
                                    potentMagAda = new potentMagAda(PotentialListAct.this, mMagList);
                                    mLvPotential.setAdapter(potentMagAda);
                                } else {
                                    //在这判断 下拉书刷新  还是上啦加载
                                    mMagList = potentMagAda.getList();
                                    if (type == 0) {
                                        //清除掉  重新刷新
                                        mMagList.clear();
                                        mMagList.addAll(potenMagInfo.getApiParamObj());
                                    } else if (type == 1) {
                                        //分页加载
                                        if (potenMagInfo.getApiParamObj().size() == 0) {
                                            UIUtils.showToastSafe("已经到达底部");
                                        } else {
                                            //滚动加载数据
                                            mMagList.addAll(potenMagInfo.getApiParamObj());
                                        }
                                    }
                                    potentMagAda.notifyDataSetChanged();
                                }
                                isRefreshing = false;
                                mLvPotential.onRefreshComplete();
                            }
                        });
                    }
                }
        );
    }

    private boolean isRefreshing = false;
    private String carModel = "";
    private String customeLevel = "";
    private int seqType = 0;
    private int pageIndex = 1;

    private int initIndex = 0;

    //上拉加载专用
    private void getBoutiqueNetData() {
        //第一次
        if (list == null) {
            list = new ArrayList<PotentialInfo.ApiParamObjEntity>();
            initIndex = 0;
        } else {
            initIndex++;
        }
        if (roleType == 1) {
            reqDataBySale(1, initIndex);
        } else if (roleType == 2 || roleType == 3) {
            return;
        } else {
            reqSearchCon(initIndex);
        }
    }

    private List<PotentialInfo.ApiParamObjEntity> mSalerList = new ArrayList<PotentialInfo.ApiParamObjEntity>();

    private void reqDataBySale(final int type, int index) {
        String strURL = String.format(UrlUtils.GETHIDDENLISt + "&SalesID=%s&CarModel=%s&CustomerLevel=%s&SeqType=%d&PageSize=10&PageIndex=%d", userId, carModel, customeLevel, seqType, index);
        volleyRequest(strURL, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                potentialInfo = JSON.parseObject(s, PotentialInfo.class);
                UIUtils.runInMainThread(new Runnable() {
                    @Override
                    public void run() {
                        if (potListadapter == null) {
                            list = potentialInfo.getApiParamObj();
                            potListadapter = new PotentialListAdapter(UIUtils.getContext(), list);
                            mLvPotential.getRefreshableView().setAdapter(potListadapter);
                        } else {
                            //在这判断 下拉书刷新  还是上啦加载
                            list = potListadapter.getList();
                            if (type == 0) {
                                //清除掉  重新刷新
                                list.clear();
                                list.addAll(potentialInfo.getApiParamObj());
                            } else if (type == 1) {
                                if (potentialInfo.getApiParamObj().size() == 0) {
                                    UIUtils.showToastSafe("已经到达底部");
                                } else {
                                    //滚动加载数据
                                    list.addAll(potentialInfo.getApiParamObj());
                                }
                            }
                            potListadapter.notifyDataSetChanged();
                        }
                        isRefreshing = false;
                        mLvPotential.onRefreshComplete();
                    }
                });
            }
        });
    }

    @Override
    protected void initListener() {
        ll_left1.setOnClickListener(this);
        mLvPotential.setOnItemClickListener(this);
        mCarSort.setOnClickListener(this);
        mCusSort.setOnClickListener(this);
        mTimeSort.setOnClickListener(this);

        mLvPotential.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            //下拉刷新
            @Override
            public void onPullDownToRefresh(
                    PullToRefreshBase<ListView> refreshView) {
//                String str = DateUtils.formatDateTime(PotentialListAct.this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
//                //设置刷新标签
//                mLvPotential.getLoadingLayoutProxy().setRefreshingLabel("正在刷新");
//                //设置下拉标签
//                mLvPotential.getLoadingLayoutProxy().setPullLabel("下拉刷新");
//                //设置释放标签
//                mLvPotential.getLoadingLayoutProxy().setReleaseLabel("释放开始刷新");
//                //设置上一次刷新的提示标签
//                refreshView.getLoadingLayoutProxy().setLastUpdatedLabel("最后更新时间:" + str);
//
//                if (!isRefreshing) {
//                    isRefreshing = true;
//                    if (roleType == 1) {
//                        reqDataByMag(0);
//                    } else {
//                        reqDataBySale(0, 0);
//                    }
//                } else {
//                    mLvPotential.onRefreshComplete();
//                }
                mLvPotential.onRefreshComplete();
            }

            //上拉加载
            @Override
            public void onPullUpToRefresh(
                    PullToRefreshBase<ListView> refreshView) {
                String str = DateUtils.formatDateTime(PotentialListAct.this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
                mLvPotential.getLoadingLayoutProxy().setRefreshingLabel("正在加载");
                mLvPotential.getLoadingLayoutProxy().setPullLabel("上拉加载更多");
                mLvPotential.getLoadingLayoutProxy().setReleaseLabel("释放开始加载");
                refreshView.getLoadingLayoutProxy().setLastUpdatedLabel("最后加载时间:" + str);

                if (!isRefreshing) {
                    isRefreshing = true;
                    getBoutiqueNetData();
                } else {
                    mLvPotential.onRefreshComplete();
                }
            }
        });


//        mLvPotential.setOnScrollListener(new AbsListView.OnScrollListener() {
//            // 滚动状态改变的监听
//            // 第二个参数表示滚动的状态
//            @Override
//            public void onScrollStateChanged(AbsListView view, int scrollState) {
//                System.out.println("onScrollStateChanged");
//                switch (scrollState) {
//                    case AbsListView.OnScrollListener.SCROLL_STATE_FLING:
//                        // 惯性状态
////					System.out.println("SCROLL_STATE_FLING");
//                        break;
//                    case AbsListView.OnScrollListener.SCROLL_STATE_IDLE:
//                        // 闲置状态
////					System.out.println("SCROLL_STATE_IDLE");
//                        int lastVisiblePosition = mLvPotential.getLastVisiblePosition();
//                        System.out.println("最后一条可见的位置---" + lastVisiblePosition);
//                        // 判断当前滚动到最后一条数据。是否是集合当中的最后一条
//                        if (lastVisiblePosition == list.size() - 1) {
//                            getBoutiqueNetData();
//                        }
//                        break;
//                    case AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
//                        // 触摸状态
////					System.out.println("SCROLL_STATE_TOUCH_SCROLL");
//                        break;
//                }
//            }
//
//            // 时时调用
//            @Override
//            public void onScroll(AbsListView view, int firstVisibleItem,
//                                 int visibleItemCount, int totalItemCount) {
//                // System.out.println("onScroll");
//            }
//        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_left1:
                finish();
                break;
            case R.id.rl_car_sort:
                /**
                 * 全部车型
                 */
                mTvCar.setTextColor(UIUtils.getColor(R.color.qianlan));
                mIvCarIcon.setImageDrawable(UIUtils.getDrawable(R.drawable.upb));
                showCarPopu();

                break;
            case R.id.rl_cus_sort:
                /**
                 * 全部级别
                 */
                mTvCus.setTextColor(UIUtils.getColor(R.color.qianlan));
                mIvCusIcon.setImageDrawable(UIUtils.getDrawable(R.drawable.upb));
                showLevPopu();
                break;
            case R.id.rl_time_sort:
                if (roleType == 1) {
                    if (seqType == 0) {
                        seqType = 1;
                        mIvTimeIcon.setImageDrawable(UIUtils.getDrawable(R.drawable.timeup));
                    } else {
                        seqType = 0;
                        mIvTimeIcon.setImageDrawable(UIUtils.getDrawable(R.drawable.timedown));
                    }
                    reqDataBySale(0, 0);
                } else {
                    if (orderBy == "asc") {
                        orderBy = "desc";
                        mIvTimeIcon.setImageDrawable(UIUtils.getDrawable(R.drawable.timeup));
                    } else {
                        orderBy = "asc";
                        mIvTimeIcon.setImageDrawable(UIUtils.getDrawable(R.drawable.timedown));
                    }
                    reqDataByMag(0);
                }
                break;
        }
    }

    public void startBackAnim(float start, float end) {
        final AlphaAnimation animation = new AlphaAnimation(start, end);
        animation.setDuration(500);//设置动画持续时间
//animation.setRepeatCount(int repeatCount);//设置重复次数
        animation.setFillAfter(true);//动画执行完后是否停留在执行完的状态
        mFlContent.setAnimation(animation);
        animation.startNow();
    }

    Handler handler = new Handler();

    private void showCarPopu() {
//        mFlContent.setVisibility(View.VISIBLE);
//        startBackAnim(0f, 0.5f);

        ListView mSpListview = initListView();
        mPwCarModel = new PopupWindow(mSpListview, width, ViewGroup.LayoutParams.WRAP_CONTENT);
        //在PopupWindow里面就加上下面代码，让键盘弹出时，不会挡住pop窗口。
//        mPwCarModel.setAnimationStyle(R.style.popwin_anim_style);
        mPwCarModel.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
        mPwCarModel.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        mPwCarModel.setFocusable(true);
        mPwCarModel.setOutsideTouchable(true);//设置点击pw以外的部分，让pw消失
        mPwCarModel.setBackgroundDrawable(UIUtils.getDrawable(R.drawable.transparent));
        mPwCarModel.showAsDropDown(mCarSort, 6, -6);

        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mFlContent.setVisibility(View.VISIBLE);
            }
        }, 160);
//                handler.postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        mRlBack.setVisibility(View.VISIBLE);
//                    }
//                }, 160);
        //添加pop窗口关闭事件
        mPwCarModel.setOnDismissListener(new popCarDisListener());
    }

    /**
     * 添加新笔记时弹出的popWin关闭的事件，主要是为了将背景透明度改回来
     *
     * @author w.pitt
     */
    class popCarDisListener implements PopupWindow.OnDismissListener {
        @Override
        public void onDismiss() {
            if (currentCarType == 0) {
                mTvCar.setTextColor(UIUtils.getColor(R.color.black));
                mIvCarIcon.setImageDrawable(UIUtils.getDrawable(R.drawable.icondown));
            }
//            startBackAnim(0.5f, 0);
            mFlContent.setVisibility(View.INVISIBLE);
        }
    }

    List<String> mLevel = new ArrayList<String>(Arrays.asList("客户级别", "N", "H", "A", "B", "C", "O"));
    List<String> mMagLevel = new ArrayList<String>(Arrays.asList("客户级别", "N", "H", "A", "B", "C", "O", "F"));
    private int currentLevel;
    private int currentCarType;

    private void showLevPopu() {

//        mFlContent.setVisibility(View.VISIBLE);
//        startBackAnim(0f, 0.5f);

        ListView lv = new ListView(this);
        lv.setVerticalScrollBarEnabled(false); //设置垂直的滚动条不可用
        lv.setBackgroundResource(R.drawable.listview_background);
        lv.setVerticalScrollBarEnabled(false);

        lv.setCacheColorHint(UIUtils.getColor(R.color.base));
        if (roleType == 1) {
            mLevels = new ArrayList<String>(Arrays.asList("客户级别", "N级", "H级", "A级", "B级", "C级", "O级"));
        } else if (roleType == 2 || roleType == 3) {
            mLevels = new ArrayList<String>(Arrays.asList("客户级别", "N级", "H级", "A级", "B级", "C级", "O级", "F级"));
        }
        downListAdapter spinnerAdapter = new downListAdapter(PotentialListAct.this, mLevels);
//        ArrayAdapter arrayAdapter = new ArrayAdapter(
//                PotentialListAct.this, android.R.layout.simple_list_item_1,
//                mLevels);
        lv.setAdapter(spinnerAdapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 0) {
                    //全部客户
                    customeLevel = "";
                } else {
                    if (roleType == 1) {
                        customeLevel = mLevel.get(position);
                    } else {
                        customeLevel = mMagLevel.get(position);
                    }
                }

                currentLevel = position;
                mTvCus.setText(mLevels.get(position));

                if (roleType == 1) {
                    initIndex = 0;
                    reqDataBySale(0, 1);
                } else {
                    reqDataByMag(0);
                }
                mPwLevel.dismiss();
            }
        });

        mPwLevel = new PopupWindow(lv, width, ViewGroup.LayoutParams.WRAP_CONTENT);
        //添加pop窗口关闭事件
        CusDisListener popCusDisLis = new CusDisListener();
        mPwLevel.setOnDismissListener(popCusDisLis);
        //在PopupWindow里面就加上下面代码，让键盘弹出时，不会挡住pop窗口。
        mPwLevel.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
        mPwLevel.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        mPwLevel.setFocusable(true);
        mPwLevel.setOutsideTouchable(true);//设置点击pw以外的部分，让pw消失
        mPwLevel.setBackgroundDrawable(UIUtils.getDrawable(R.drawable.transparent));
        mPwLevel.showAsDropDown(mCarSort, 6, -6);

        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mFlContent.setVisibility(View.VISIBLE);
            }
        }, 160);
//                handler.postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        mRlBack.setVisibility(View.VISIBLE);
//                    }
//                }, 160);

    }

    /*
   填充 popuwindow  listview
    */
    private ListView initListView() {
        ListView lv = new ListView(this);
        lv.setVerticalScrollBarEnabled(false); //设置垂直的滚动条不可用
        lv.setBackgroundResource(R.drawable.listview_background);
        lv.setCacheColorHint(UIUtils.getColor(R.color.base));
//        initListivewData();
//        ArrayAdapter arrayAdapter = new ArrayAdapter(
//                PotentialListAct.this, android.R.layout.simple_list_item_1,
//                mDatas);
//        CarModekAdp adapter = new CarModekAdp(mDatas);

        downListAdapter spinnerAdapter = new downListAdapter(PotentialListAct.this, mDatas);
        lv.setAdapter(spinnerAdapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 0) {
                    //全部车型
                    carModel = "";
                } else {
                    carModel = mDatas.get(position);
                }
                currentCarType = position;
                mTvCar.setText(mDatas.get(position));

                if (roleType == 1) {
                    initIndex = 0;
                    reqDataBySale(0, 1);
                } else {
                    reqDataByMag(0);
                }
                mPwCarModel.dismiss();
            }
        });
        return lv;
    }

    private List<String> mDatas = new ArrayList<String>(Arrays.asList("全部车型"));
    //    private void initListivewData() {
//        mDatas.add("车没数据");
//    }
    private String customerID;
    private String createTime;
    private String salerName;

    /**
     * @param adapterView
     * @param view
     * @param position
     * @param l
     */
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        Intent intent = new Intent(this, ClientDetailAct.class);
        if (roleType == 1) {
            customerID = list.get(position - 1).getCustomerID();
            carModel = list.get(position - 1).getCarModel();
            createTime = list.get(position - 1).getCreateTime();
        } else {
            customerID = mMagList.get(position - 1).getCustomerID();
            carModel = mMagList.get(position - 1).getCarModel();
            createTime = mMagList.get(position - 1).getLastTime();
            salerName = mMagList.get(position - 1).getRealName();
        }
        intent.putExtra("CarModel", carModel);
        intent.putExtra("CustomerID", customerID);
        intent.putExtra("CreateTime", createTime);
        intent.putExtra("SalerName", salerName);
        startActivity(intent);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
            /*隐藏软键盘*/
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (inputMethodManager.isActive()) {
                inputMethodManager.hideSoftInputFromWindow(PotentialListAct.this.getCurrentFocus().getWindowToken(), 0);
            }
            if (TextUtils.isEmpty(mEtSearch.getText().toString())) {
                UIUtils.showToastSafe("请输入搜索内容");
            } else {
                reqSearchCon(0);
            }
            return true;
        }
        return super.dispatchKeyEvent(event);
    }

    private List<SearchPotenInfo.ApiParamObjEntity> searchList;

    /**
     * 潜客 搜索
     */
    private void reqSearchCon(int pageIndex) {
        String secData = mEtSearch.getText().toString().trim();
        String strURL = String.format(UrlUtils.GETSAlESPASLIST + "&SalesID=%s&Str=%s&PageSize=%d&PageIndex=%d", userId, secData, 10, pageIndex);
        volleyRequest(strURL, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                searchPotenInfo = JSON.parseObject(s, SearchPotenInfo.class);
                UIUtils.runInMainThread(new Runnable() {
                    @Override
                    public void run() {
                        if (searchPotenInfo.getCount() == 0) {
                            UIUtils.showToastSafe("未搜索到数据");
                        } else {
                            if (potentialAdapter == null) {
                                searchList = searchPotenInfo.getApiParamObj();
                                potentialAdapter = new PotentialAdapter(UIUtils.getContext(), searchList);
                                mLvPotential.setAdapter(potentialAdapter);
                            } else {
                                potentialAdapter.getList();
                                //分页加载
                                if (potentialInfo.getApiParamObj().size() == 0) {
                                    UIUtils.showToastSafe("已经到达底部");
                                } else {
                                    //滚动加载数据
                                    searchList.addAll(searchPotenInfo.getApiParamObj());
                                    potentialAdapter.notifyDataSetChanged();
                                }
                            }
                            isRefreshing = false;
                            mLvPotential.onRefreshComplete();
                        }
                    }
                });
            }
        });
    }

    private class CusDisListener implements PopupWindow.OnDismissListener {
        @Override
        public void onDismiss() {
            if (currentLevel == 0) {
//                mRlBack.setVisibility(View.INVISIBLE);
                mTvCus.setTextColor(UIUtils.getColor(R.color.black));
                mIvCusIcon.setImageDrawable(UIUtils.getDrawable(R.drawable.icondown));
            }
//            startBackAnim(0.5f, 0);
            mFlContent.setVisibility(View.INVISIBLE);
        }
    }
}
